package components.tools.photos
{
	import SEApp.boxes.albums.se_userAvatar;
	
	import UIFree.ObjectEvent;
	import UIFree.controls.uif_arrowbutton;
	import UIFree.controls.uif_button;
	import UIFree.controls.uif_hscrollArea;
	import UIFree.controls.uif_leavesBlock;
	import UIFree.controls.uif_popupMenu;
	import UIFree.uif_Timer;
	import UIFree.uif_component;
	
	import classes.clt_events;
	
	import components.clt_leftLeaveBlock;
	import components.clt_popupMenu;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class clt_userAvatar extends se_userAvatar {
		private var _addedLayer		: uif_leavesBlock;
		private var _startRect		: Rectangle;
		private var _focus			: Boolean;
		private var _menu			: uif_popupMenu;
		
		protected var _button		: uif_arrowbutton;
		
		public function clt_userAvatar(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, userData: Object=null, styleClass:String='')	{
			super(parent, ax, ay, awidth, aheight, userData, styleClass);
			//if (_dataItem) createComponents();
		}
		
		override protected function createComponents(): void {
			super.createComponents();
			if (data) {
				var inner: Rectangle = getInner();
				_addedLayer = new clt_leftLeaveBlock(this, inner.x - 28, inner.y, 25, 40);
				addEvent(MouseEvent.ROLL_OVER, function(e: MouseEvent): void {
					_focus = true;
					uif_Timer.one(500, function(e: Event): void {
						if (_focus) {
							_addedLayer.show();
							if (isLeft) {
								if (!_startRect) _startRect = This.getOuter();
								fx('left', left, _startRect.x + 25).start();
							}
						}
					});
				});
				addEvent(MouseEvent.ROLL_OUT, function(e: MouseEvent): void {
					if (_focus) {
						_addedLayer.hide();
						if (isLeft && _startRect) fx('left', left, _startRect.x).start();
					}
					_focus = false;
				});

				inner = _addedLayer.EnterHere(new Point(20, 20));
				_button = new uif_arrowbutton(_addedLayer.block, inner.x, inner.y, inner.width, inner.height, 3, 'farrow');
				_button.addEvent(MouseEvent.CLICK, buttonRelease);
				
				var menuList: Array = getMenuList();
				if (menuList) {
					_menu = new clt_popupMenu(clt.popupMenuLayer, _button, menuList, onMenuItemSelect);
				}
			}
		}
		
		protected function onMenuItemSelect(e: ObjectEvent): void {
			this[e.object.method]();
		}
		
		protected function get menu(): uif_popupMenu {
			return _menu;
		} 
		
		protected function getMenuList(): Array {
			return null;
		}
		
		protected function buttonRelease(e: MouseEvent): void {
			clt.workspace.dispatchEvent(new ObjectEvent(clt_events.SHOWUSERPHOTOS, _dataItem));
		}
		
		public function get isLeft(): Boolean {
			return scrollArea && (scrollArea.scrollArea.x + x <= width); 
		}
		
		public function get scrollArea(): uif_hscrollArea {
			return (parent?(parent.parent as uif_hscrollArea):null);
		}
		
		public function get clt(): clt_clothingBase {
			return app as clt_clothingBase;
		}
		
		public function get left(): Number {
			return x;
		}

		public function set left(a_left: Number): void {
			x 		= a_left;
			width 	= _startRect.right - x;
		}
	}
}